package com.zwr.sheller.customer.controller;

import com.zwr.sheller.core.common.JsonResult;
import com.zwr.sheller.core.common.WQQBusinessException;
import com.zwr.sheller.customer.Service.GoodsService;
import com.zwr.sheller.customer.Service.ItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author: 18032
 * @Date: 9:41 2022/1/14
 */
@RestController
@CrossOrigin
@Api(tags = "首页下方点击分类和首页点击夏季水果")
@RequestMapping("/item")
public class ItemController {

    @Autowired(required = false)
    ItemService itemService;
    @Autowired(required = false)
    GoodsService goodsService;

    @ApiOperation("首页点击分类出现一二三级分类")
    @PostMapping("/sort")
    private Map<String, Object> selectSort() throws WQQBusinessException {
        List<Map<String, Object>> list = itemService.selectSort();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("data", list);
        jsonResult.setCode("200");
        return jsonResult.getMap();
    }

    @ApiOperation("夏季水果点击分类出现二三级分类")
    @PostMapping("/secondAndThirdSort")
    private Map<String, Object> secondAndThirdSort(Long item_id) throws WQQBusinessException {
        List<Map<String, Object>> list = itemService.selectSort();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("data", list);
        jsonResult.setCode("200");
        return jsonResult.getMap();
    }

    @ApiOperation("根据分类出现不同的商品")
    @PostMapping("/selectGoods")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemId",value = "种类id",dataType = "Long",required = true),
            @ApiImplicitParam(name = "rankId",value = "种类等级,1.一级品类;2.2级品类;3.三级品类",dataType = "Long",required = true),
            @ApiImplicitParam(name = "numOrder",value = "按照销量排序true:升序,false降序",dataType = "Boolean",required = false),
            @ApiImplicitParam(name = "priceOrder",value = "按照价格排序,true:升序,false降序",dataType = "Boolean",required = false),
            @ApiImplicitParam(name = "choose",value = "标签选择:1.推荐 2. 新品 3. 热卖",dataType = "Double",required = false),
            @ApiImplicitParam(name = "lowPrice",value = "最低价格",dataType = "Double",required = false),
            @ApiImplicitParam(name = "highPrice",value = "最高价格",dataType = "Double",required = false)
    })
    private Map<String, Object> selectGoods(Long itemId, Long rankId, Boolean numOrder, Boolean priceOrder, Long choose, Double lowPrice, Double highPrice) throws WQQBusinessException {
        List<Map<String, Object>> list = goodsService.selectGoodsBySortAndPrice(itemId, rankId, numOrder, priceOrder, choose, lowPrice, highPrice);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setField("data", list);
        jsonResult.setCode("200");
        return jsonResult.getMap();
    }

}
